package com.atguigu.search;

import static java.util.Arrays.binarySearch;

public class binarysearch {
    public static int binarySearch(int[]arraySorted,int target ){
        int left = 0;
        int right = arraySorted.length-1;
        while (left <= right){
            int middle = left+ (right - left)/2;
            if (arraySorted[middle] == target){
                return middle;
            } else if (arraySorted[middle] > target) {
                right = middle-1;
            }else {
                left = middle+1;
            }

        }
        return -1;
    }

    public static void main(String[] args) {
        int []arrays = new int []{1,11,22,33,77,99,103,111};
        int target = 33;
        System.out.println(binarySearch(arrays, target));
    }
}
